<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="html"/>
  <xsl:template match="/">
    <xsl:variable name="PID">
      <xsl:choose>
        <xsl:when test="/Toolkit/_TREE_NODE_PARENT_INFO/ROOT_INFO">
          <xsl:value-of select="/Toolkit/_TREE_NODE_PARENT_INFO/ROOT_INFO"/>
        </xsl:when>
        <xsl:when test="/Toolkit/QueryString/PID">
          <xsl:value-of select="/Toolkit/QueryString/PID"/>
        </xsl:when>
      </xsl:choose>
    </xsl:variable>
    <xsl:choose>
      <xsl:when test="$PID">
        <xsl:call-template name="TreeNode">
          <xsl:with-param name="PID" select="$PID"/>
        </xsl:call-template>
      </xsl:when>
      <xsl:otherwise>
        <xsl:call-template name="TreeNode">
          <xsl:with-param name="PID" select="'-1'"/>
        </xsl:call-template>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
  <xsl:template name="TreeNode">
    <xsl:param name="PID"/>
    <xsl:for-each select="/Toolkit/_TREE[PID = $PID]">
      <xsl:variable name="ID" select="ID"/>
      <xsl:variable name="HasNext" select="count(/Toolkit/_TREE[PID = $ID])"/>
      <div class="TreeNode" style="width:200px;" nowrap="true" onDragStart="event.dataTransfer.effectAllowed='move'; event.dataTransfer.dropEffect='move';event.dataTransfer.setData('TEXT', this.uid);" ondrop="if(confirm('是否真要移动节点?')) MoveNode(event.dataTransfer.getData('TEXT'),this.uid)" ondragover="event.returnValue=false; event.cancelBubble=true;">
        <xsl:attribute name="uid">
          <xsl:value-of select="ID"/>
        </xsl:attribute>
        <xsl:choose>
          <xsl:when test="not(ISLEAF = 1)">
            <xsl:attribute name="type">parent</xsl:attribute>
            <xsl:attribute name="open">false</xsl:attribute>
          </xsl:when>
          <xsl:otherwise>
            <xsl:attribute name="type">leaf</xsl:attribute>
          </xsl:otherwise>
        </xsl:choose>
        <img id="imgExpand" type="img" align="absmiddle" onclick="MouseClick();">
          <xsl:attribute name="src">
            <xsl:choose>
              <xsl:when test="not(ISLEAF = 1) and $HasNext = 0">../images2/folder.gif</xsl:when>
              <xsl:when test=" $HasNext > 0 ">../images2/folderopen.gif</xsl:when>
              <xsl:otherwise>../images2/file.gif</xsl:otherwise>
            </xsl:choose>
          </xsl:attribute>
        </img>
        <a type="label" style="text-decoration:none;cursor:hand;" href="#" onclick="ShowDetail('{ID}');return false">
          <xsl:value-of select="NAME"/>
        </a>
      </div>
      <xsl:if test="not(ISLEAF = 1)">
        <xsl:choose>
          <xsl:when test="$HasNext > 0">
            <div style="padding-left:14;" send="true">
              <xsl:call-template name="TreeNode">
                <xsl:with-param name="PID" select="$ID"/>
              </xsl:call-template>
            </div>
          </xsl:when>
        </xsl:choose>
        <div style="padding-left:14;display:none" send="false"/>
      </xsl:if>
    </xsl:for-each>
  </xsl:template>
  <xsl:template match="message">
    <div class="TreeNode" type="leaf" nowrap="true">
      <img id="imgCollapse" type="img" src="../images2/file.gif" align="absmiddle"/>
      <span type="load" class="load">
        <xsl:value-of select="@txt"/>
      </span>
    </div>
  </xsl:template>
</xsl:stylesheet>
